<%--
  Created by IntelliJ IDEA.
  User: notyoukennk
  Date: 2022/11/20
  Time: 21:13
  To change this template use File | Settings | File Templates.
--%>
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="ProjectManagement.DobConn" %>
<html>
<head>
    <title>删除留言</title>
    <style>
        body{
            margin: 0;
        }
        .box{
            width: 100%;
            height: 100%;
            display: flex;
            align-items: center;
            justify-content: center;
            background: linear-gradient(#5489d0, #ee61a8);
        }
        .delete{
            font-size: 2em;
            color: azure;
        }
    </style>

</head>
<body>

<%
    try{

        String username = (String) session.getAttribute("username");
        Connection conn = DobConn.getConn();
        Statement stat = conn.createStatement();
        Statement stat1 = conn.createStatement();
        String num = request.getParameter("num");//获取留言编号
        String sql1 = "SELECT * FROM messages WHERE num ='"+num+"'";
        ResultSet rs = stat1.executeQuery(sql1);
        while(rs.next()){
            if(rs.getString("username").equals(username)){
                num = new String(num.getBytes());
                System.out.print("num="+num);
                String sql = "DELETE FROM messages WHERE num ='"+num+"';";
                int i = stat.executeUpdate(sql);
                response.setHeader("refresh", "3;URL=messageboard.jsp");//三秒后返回留言界面
                out.print("<div class='box'><div class='delete'>已删除！</div>" + "<div class='delete'>3秒后返回</div></div>");
            }else{
                out.print("<div class='box'><div class='delete'>不能删除其他用户的留言哦！</div>" + "<div class='delete'>3秒后返回</div></div>");
                response.setHeader("refresh", "3;URL=messageboard.jsp");
            }
        }
    }catch (SQLException e){
        System.out.print(e);
    }
%>
</body>
</html>
